const path = require('path');
const fs = require('fs');
const Koa = require('koa2');
const staticCache = require('koa-static-cache');

const resolve = (pn) => path.join(__dirname, pn);

const app = new Koa();

const port = process.env.PORT || 8080;

const cacheOpts = { dynamic: true, maxAge: 7 * 24 * 60 * 60 };

app.use(staticCache(resolve('static'), cacheOpts));
app.use(staticCache(resolve('assets'), { ...cacheOpts, prefix: '/assets' }));

app.on('error', (err) => {
  console.error('server error', err);
});

//启动服务
app.listen(port, () => {
  console.log('\n\n koa服务已启动，监听:', `http://0.0.0.0:${port}\n`);
});
